#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/8/3 19:52
# @Author  : Sun
# @File    : mis_login.py
# @Software: PyCharm
import json

import requests

from common.read_yaml import ReadYaml


class MisLogin:
    _URL = 'https://mis.jjmatch.cn/cfrm/v3/api/logging/in'
    _DATA = json.dumps({
        "Account": "sunaj01",
        "Password": "Jun333333",
        "Totptoken": ""
    })
    _HEADERS = {
        'Host': 'mis.jjmatch.cn',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36',
        'content-type': 'application/json',
        'accept': '*/*',
        'origin': 'https://mis.jjmatch.cn',
        'sec-fetch-site': 'same-origin',
        'sec-fetch-mode': 'cors',
        'sec-fetch-dest': 'empty',
        'referer': 'https://mis.jjmatch.cn/v3/',
        'accept-language': 'zh-CN,zh;q=0.9'
    }

    def __init__(self):
        self.mis_login()

    # request(method, url, **kwargs)
    def mis_login(self):
        # 先清空一下Yaml文件
        ReadYaml().clear_yaml(file_path='./config/mis_cookie.yaml')
        r = requests.request('POST', url=self._URL, headers=self._HEADERS, data=self._DATA)
        mis_cookies = r.cookies.items()
        ReadYaml().write_yaml(file_path='./config/mis_cookie.yaml', data=mis_cookies)
        for key, value in r.cookies.items():
            print(key, value)
        return r.cookies


if __name__ == '__main__':
    login = MisLogin()
    login.mis_login()
